package com.mall.service.marketing.controller;

import com.mall.commons.common.CommonResult;
import com.mall.model.domain.SmsFlashPromotionSession;
import com.mall.model.vo.WangHaoVO;
import com.mall.service.marketing.service.FlashService;
import com.mall.service.marketing.service.FlashSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName FlashSessionController
 * @Description 场次 控制器
 * @Author Young
 * @Date 2023/3/12 12:33
 * @Version 1.0
 */
@RestController
@RequestMapping("/flashSession")
public class FlashSessionController {

    @Autowired
    private FlashSessionService flashSessionService;

    /**
     *添加场次
     * @param sfps
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody SmsFlashPromotionSession sfps){
        flashSessionService.create(sfps);
        return CommonResult.success(1,"添加成功");
    }

    /**
     * 删除场次
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id){
        flashSessionService.delete(id);
        return CommonResult.success(1,"删除成功");
    }

    /**
     * 获取全部场次
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(){
        List<SmsFlashPromotionSession> list = flashSessionService.list();
        return CommonResult.success(list,"");
    }

    /**
     * 获取全部可选场次及其数量
     * @param flashPromotionId
     * @return
     */
    @GetMapping("/selectList")
    public CommonResult selectList(Integer flashPromotionId){
        List<WangHaoVO> sfpsList = flashSessionService.selectList(flashPromotionId);
        return CommonResult.success(sfpsList,"");
    }

    /**
     * 修改启用状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("update/status/{id}")
    public CommonResult updateStatus(@PathVariable Integer id, Integer status){
        flashSessionService.updateStatus(id,status);
        return CommonResult.success(1,"");
    }

    /**
     * 修改场次
     * @param id
     * @param sfps
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult updateId(@PathVariable Integer id,@RequestBody SmsFlashPromotionSession sfps){
        flashSessionService.updateId(id,sfps);
        return CommonResult.success(1,"");
    }

    /**
     * 获取场次详情
     * @param id
     * @return
     */
    @PostMapping("/{id}")
    public CommonResult get(@PathVariable Integer id){
        SmsFlashPromotionSession sfps= flashSessionService.get(id);
        return CommonResult.success(sfps,"");
    }

}
